@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.goodsList')}}">商品列表</a>
            <em> > </em>
            <a href="#">评论列表</a>
        </div>


        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户昵称</th>
                    <th>用户图片</th>
                    <th>商品名称</th>
                    <th>评论内容</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($comments) > 0)
                    @foreach($comments as $comment)
                        <tr id="comment_{{$comment->id}}">
                            <td>{{$comment->id}}</td>
                            <td>{{$comment->nickname}}</td>
                            <td class="account-td" style="width: 5%;">
                        <span class="photo" style="border-radius: 100%;display:initial">
                            <a target="_blank" href="{{$comment->photo_url}}" class="openimg" data-key="{{$comment->photo_url}}"><img src="{{$comment->photo_url}}" alt=""></a>
                        </span>
                            </td>
                            <td>{{$comment->goods_name}}</td>
                            <td>{{$comment->content}}</td>
                            <td>
                                <a href="{{route('Admin.Home.goodsCommentImgList')}}?id={{$comment->id}}&goods_id={{$comment->goods_id}}" class="color2">查看图片</a> <span>|</span>
                                <a href="javascript:void(0);" data-id="{{$comment->id}}" style="color: #ef1414;" onclick="upPop('{{$comment->id}}','{{$classify->name}}','{{$classify->sort}}')">编辑</a> |


                                <a href="javascript:void(0);" class="del" data-id="{{$comment->id}}">删除 </a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $comments->appends(['id' => $goodsId])->render(); ?>
        </div>
    </div>



    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.goods.delGoodsComment')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#comment_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });

            });
        });
    </script>
@endsection